home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Viewer How-To CD / Microsoft Multimedia Viewer How-To CD.iso / mvsample / progsamp / eplist / graphics.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  4KB  |  158 lines

  1. #include <windows.h>
  2. #include "graphics.h"
  3.  
  4. /************************************************************************
  5.  * MakeFont: Create a logical font using the specified hdc, typeface and
  6.  *           font size.
  7.  ************************************************************************/
  8.  
  9. HFONT MakeFont(HDC hdc, LPSTR lpszFace, WORD wSize)
  10. {
  11.     PLOGFONT plf;
  12.     HFONT    hfont;
  13.  
  14.     plf = (PLOGFONT)LocalAlloc(GPTR, sizeof(LOGFONT));
  15.  
  16.     if(plf == NULL) return NULL;
  17.  
  18.     plf->lfHeight = -MulDiv(wSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  19.  
  20.     lstrcpy(plf->lfFaceName, lpszFace);
  21.  
  22.     plf->lfWeight = FW_NORMAL;
  23.  
  24.     hfont = CreateFontIndirect(plf);    
  25.  
  26.     LocalFree((LOCALHANDLE)plf);
  27.  
  28.     return hfont;
  29. }
  30.  
  31.  
  32.  
  33. /************************************************************************
  34.  * RectBorder: Draw a shadowed box border.
  35.  *
  36.  ************************************************************************/
  37.  
  38. int RectBorder(
  39.     HDC hDC,                    // Where to draw border
  40.     LPRECT lprc,                // Top, Left and Bottom, Right coordinates
  41.     int nWidth)                 // Width of bevel
  42. {
  43.     HPEN hPen1, hPen2, hPen3, hOldPen;
  44.     HBRUSH hOldBrush;
  45.     int i;
  46.     RECT  rc;
  47.  
  48.     CopyRect(&rc, lprc);
  49.  
  50.     hOldPen = SelectObject(hDC, GetStockObject(BLACK_PEN));
  51.     hOldBrush = SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  52.  
  53.     Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom );
  54.  
  55.     rc.left   += 1;
  56.     rc.top    += 1;
  57.     rc.bottom -= 1;
  58.     rc.right  -= 1;
  59.  
  60.     // Draw top and left
  61.     hPen1 = CreatePen(PS_SOLID, 0, RGBWhite);
  62.     SelectObject(hDC, hPen1);
  63.     for (i = 0; i < nWidth; i++)
  64.     {
  65.         MoveTo(hDC, rc.left,   rc.top+i);
  66.         LineTo(hDC, rc.right,  rc.top+i);
  67.         MoveTo(hDC, rc.left+i, rc.top+nWidth);
  68.         LineTo(hDC, rc.left+i, rc.bottom);
  69.     }
  70.  
  71.     // Draw bottom and right
  72.     hPen2 = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));
  73.     SelectObject(hDC, hPen2);
  74.     for ( i = 1; i <= nWidth; i++)
  75.     {
  76.         MoveTo(hDC, rc.left+i,  rc.bottom-i);
  77.         LineTo(hDC, rc.right,   rc.bottom-i);
  78.         MoveTo(hDC, rc.right-i, rc.bottom-nWidth);
  79.         LineTo(hDC, rc.right-i, rc.top+i-1);
  80.     }
  81.  
  82.     hPen3 = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNFACE));
  83.     SelectObject(hDC, hPen3);
  84.     SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  85.  
  86.     Rectangle(hDC, rc.left+nWidth+1,  rc.top+nWidth+1, 
  87.                    rc.right-nWidth-1, rc.bottom-nWidth-1);
  88.  
  89.     SelectObject(hDC, hOldPen);
  90.     SelectObject(hDC, hOldBrush);
  91.  
  92.     DeleteObject(hPen1);
  93.     DeleteObject(hPen2);
  94.     DeleteObject(hPen3);
  95.  
  96.     return 0;
  97. }
  98.  
  99.  
  100. /*************************************************************************
  101.  * DrawList: Draws the text list in the specified location
  102.  *************************************************************************/
  103.  
  104. void DrawList(
  105.     HDC hdc,            // Device context
  106.     int x, int y,       // Origin of text list
  107.     LPRECT lprc,        // Clipping rectangle
  108.     LPSTR FAR *lplist,  // List to draw
  109.     int nTop,           // Topmost element to draw
  110.     int nCur,           // Current selection
  111.     int nList)          // Count of elements in list
  112. {
  113.     RECT  rcClip;
  114.  
  115.     TEXTMETRIC tm;
  116.  
  117.     int  iLineSpace;
  118.     int  i;
  119.  
  120.     SelectObject(hdc, GetStockObject(BLACK_PEN));
  121.     SelectObject(hdc, GetStockObject(WHITE_BRUSH));
  122.  
  123.     SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  124.     SetBkColor(hdc,   GetSysColor(COLOR_WINDOW));
  125.  
  126.     GetTextMetrics(hdc, &tm);
  127.  
  128.     iLineSpace = tm.tmHeight + tm.tmExternalLeading;
  129.  
  130.     CopyRect(&rcClip, lprc);
  131.  
  132.     for(i = nTop; i < nList && y < lprc->bottom; i++)
  133.     {
  134.         rcClip.top    = y;
  135.         rcClip.bottom = min(y + iLineSpace, lprc->bottom);
  136.  
  137.         if(rcClip.bottom >= lprc->top)
  138.         {    
  139.             if(i == nCur)
  140.             {
  141.                 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
  142.                 SetBkColor(hdc,   GetSysColor(COLOR_HIGHLIGHT));
  143.             }
  144.  
  145.             ExtTextOut(hdc, x, y, 
  146.                 ETO_CLIPPED | ETO_OPAQUE, &rcClip,
  147.                 lplist[i], lstrlen(lplist[i]), NULL); 
  148.  
  149.             if(i == nCur)
  150.             {
  151.                 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  152.                 SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  153.             }
  154.         }
  155.         y += iLineSpace;
  156.     }
  157. }
  158.